package com.tarena.lbs.article.web.service;

import com.tarena.lbs.article.web.repository.ArticleCatsRepository;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.basic.po.ArticleCategoryPO;
import com.tarena.lbs.pojo.content.vo.ArticleCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ArticleCatsService {
    @Autowired
    private ArticleCatsRepository articleCatsRepository;
    public PageResult<ArticleCategoryVO> categoryList() {
        //1.从仓储层拿到pos
        List<ArticleCategoryPO> pos=articleCatsRepository.findAll();
        //2.转化vos
        List<ArticleCategoryVO> vos=
                pos.stream().map(po->{
                    ArticleCategoryVO vo=new ArticleCategoryVO();
                    BeanUtils.copyProperties(po,vo);
                    return vo;
                }).collect(Collectors.toList());
        //3.查询分类的分页数据封装
        PageResult<ArticleCategoryVO> voPage=new PageResult<>();
        voPage.setPageNo(1);
        voPage.setPageSize(10);
        voPage.setTotal(3l);
        voPage.setObjects(vos);
        return voPage;
    }
}
